﻿#include "COptPdfRptBase.h"
#include "CTaskExecInfo.h"
#include "CDevDataBase.h"
#include <QElapsedTimer>
#include "CHeader.h"

COptPdfRptBase::COptPdfRptBase(QObject *parent)
	: QObject(parent)
{

}


//获取两点托辊号之间的 连续红外检测数据、连续噪声检测数据
void COptPdfRptBase::getBetwTwoRollerCotData(int nStartRoller, int nEndRoller, QMap<int, QVector<CPdfCotIrInfo>> &mapCotIr, QMap<int, QVector<CPdfCotVoiceInfo>> &mapCotVoice, QVector<CPdfCotIrInfo> &vecAllCotIr, QVector<CPdfCotVoiceInfo> &vecAllCotVoice)
{
	if (nStartRoller > nEndRoller)//开始托辊号大于结束托辊号，则返回
	{
		return;
	}
	for (int i = 0; i < vecAllCotIr.size(); i++)
	{
		if (vecAllCotIr[i].m_nRollerCode >= nStartRoller && vecAllCotIr[i].m_nRollerCode < nEndRoller)
		{
			if (mapCotIr.contains(vecAllCotIr[i].m_nRollerCode))
			{
				// 获取对应的 QVector
				QVector<CPdfCotIrInfo> &vecData = mapCotIr[vecAllCotIr[i].m_nRollerCode];
				vecData.append(vecAllCotIr[i]);
			}
			else
			{
				QVector<CPdfCotIrInfo> vecData;
				vecData.append(vecAllCotIr[i]);
				mapCotIr.insert(vecAllCotIr[i].m_nRollerCode, vecData);
			}
		}
	}
}

//获取连续检测红外Map数据
void COptPdfRptBase::getCotMapIrData(QMap<int, QVector<CPdfCotIrInfo>> &mapCotIr, QVector<CPdfCotIrInfo> &vecAllCotIr)
{
	for (int i = 0; i < vecAllCotIr.size(); i++)
	{
		if (mapCotIr.contains(vecAllCotIr[i].m_nRollerCode))
		{
			// 获取对应的 QVector
			QVector<CPdfCotIrInfo> &vecData = mapCotIr[vecAllCotIr[i].m_nRollerCode];
			vecData.append(vecAllCotIr[i]);
		}
		else
		{
			QVector<CPdfCotIrInfo> vecData;
			vecData.append(vecAllCotIr[i]);
			mapCotIr.insert(vecAllCotIr[i].m_nRollerCode, vecData);
		}
	}
}

//获取连续检测声音Map数据
void COptPdfRptBase::getCotMapVoiceData(QMap<int, QVector<CPdfCotVoiceInfo>> &mapCotVoice, QVector<CPdfCotVoiceInfo> &vecAllCotVoice)
{
	for (int i = 0; i < vecAllCotVoice.size(); i++)
	{
		if (mapCotVoice.contains(vecAllCotVoice[i].m_nRollerCode))
		{
			// 获取对应的 QVector
			QVector<CPdfCotVoiceInfo> &vecData = mapCotVoice[vecAllCotVoice[i].m_nRollerCode];
			vecData.append(vecAllCotVoice[i]);
		}
		else
		{
			QVector<CPdfCotVoiceInfo> vecData;
			vecData.append(vecAllCotVoice[i]);
			mapCotVoice.insert(vecAllCotVoice[i].m_nRollerCode, vecData);
		}
	}
}

//获取连续检测图像Map数据
void COptPdfRptBase::getCotMapImageData(QMap<int, QVector<CPdfCotImageInfo>> &mapCotImage, QVector<CPdfCotImageInfo> &vecAllCotImage)
{
	for (int i = 0; i < vecAllCotImage.size(); i++)
	{
		if (mapCotImage.contains(vecAllCotImage[i].m_nRollerCode))
		{
			// 获取对应的 QVector
			QVector<CPdfCotImageInfo> &vecData = mapCotImage[vecAllCotImage[i].m_nRollerCode];
			vecData.append(vecAllCotImage[i]);
		}
		else
		{
			QVector<CPdfCotImageInfo> vecData;
			vecData.append(vecAllCotImage[i]);
			mapCotImage.insert(vecAllCotImage[i].m_nRollerCode, vecData);
		}
	}
}

//计算连续检测结果归属层级
void COptPdfRptBase::calculateCotRetBelongTier(QMap<int, QVector<CPdfCotIrInfo>> &mapCotIr, QMap<int, QVector<CPdfCotVoiceInfo>> &mapCotVoice, QMap<int, QVector<CPdfCotImageInfo>> &mapCotImage)
{
	//一个Int托辊对应的QVector是两个数据,时间小的是去程 时间大的是归程
	//一个托辊号 对应QVector中的两条数据
	for (QMap<int, QVector<CPdfCotIrInfo>>::iterator i = mapCotIr.begin(); i != mapCotIr.end(); i++)
	{
		QVector<CPdfCotIrInfo> &vecData = i.value();

		if (vecData.size() >= 2)
		{
			qint64 timestamp1 = vecData[0].m_dtActionTime.toSecsSinceEpoch();
			qint64 timestamp2 = vecData[1].m_dtActionTime.toSecsSinceEpoch();
			if (timestamp1 < timestamp2)
			{
				vecData[0].nBelongTier = 0;//归属层级 0:去程 1:归程
				vecData[1].nBelongTier = 1;
			}
			else
			{
				vecData[0].nBelongTier = 1;//归属层级 0:去程 1:归程
				vecData[1].nBelongTier = 0;
			}
		}
	}

	for (QMap<int, QVector<CPdfCotVoiceInfo>>::iterator i = mapCotVoice.begin(); i != mapCotVoice.end(); i++)
	{
		QVector<CPdfCotVoiceInfo> &vecData = i.value();

		if (vecData.size() >= 2)
		{
			qint64 timestamp1 = vecData[0].m_dtActionTime.toSecsSinceEpoch();
			qint64 timestamp2 = vecData[1].m_dtActionTime.toSecsSinceEpoch();
			if (timestamp1 < timestamp2)
			{
				vecData[0].nBelongTier = 0;//归属层级 0:去程 1:归程
				vecData[1].nBelongTier = 1;
			}
			else
			{
				vecData[0].nBelongTier = 1;//归属层级 0:去程 1:归程
				vecData[1].nBelongTier = 0;
			}
		}
	}

	for (QMap<int, QVector<CPdfCotImageInfo>>::iterator i = mapCotImage.begin(); i != mapCotImage.end(); i++)
	{
		QVector<CPdfCotImageInfo> &vecData = i.value();

		if (vecData.size() >= 2)
		{
			qint64 timestamp1 = vecData[0].m_dtActionTime.toSecsSinceEpoch();
			qint64 timestamp2 = vecData[1].m_dtActionTime.toSecsSinceEpoch();
			if (timestamp1 < timestamp2)
			{
				vecData[0].nBelongTier = 0;//归属层级 0:去程 1:归程
				vecData[1].nBelongTier = 1;
			}
			else
			{
				vecData[0].nBelongTier = 1;//归属层级 0:去程 1:归程
				vecData[1].nBelongTier = 0;
			}
		}
	}
}

//绘制新的一个连续红外
void COptPdfRptBase::drawNewPageCotIr(QMap<int, QVector<CPdfCotIrInfo>> &mapCotIrInfo, QPainter &painter, QPrinter &printer)
{
	QPen penNormal(Qt::black, 1, Qt::SolidLine);// 设置边框的颜色和宽度 正常黑色
	QPen penNormalRed(Qt::red, 1, Qt::SolidLine);// 设置边框的颜色和宽度 正常红色
	QPen penJiaCu(Qt::black, 3, Qt::SolidLine);// 设置边框的颜色和宽度 正常黑色加粗

	QFont fontPage2Normal("Arial", 18, QFont::Normal);//普通
	QFont fontPage2Red("Arial", 18, QFont::Bold);//普通红色
	QFont fontPage2SmallNormal("Arial", 12, QFont::Normal);//普通
	QFont fontPage2JiaCu("Arial", 18, QFont::Bold);//加粗
	QFont fontPage2SmallJiaCu("Arial", 14, QFont::Bold);//加粗
	QFont fontPage2Bold("Arial", 24, QFont::Bold);//加粗

	QString strTableCaption = "";

	//先统计总数
	int nCount = 0;
	for (QMap<int, QVector<CPdfCotIrInfo>>::iterator i = mapCotIrInfo.begin(); i != mapCotIrInfo.end(); i++)
	{
		nCount += i.value().size();
	}


	//先计算A4纸是否满足 不然就要自定义高度
	if (nCount > 3)//异常信息列表大于3行,A4纸大小就不够了
	{
		//int nPageHeightVal = 297 + (CRobData.m_VecCotVoiceInfo.size() - 21 + 1) * 11;//这个大小测试的适配成功
		int nPageHeightVal = 297 + (nCount * 6 - 21 + 1) * 11;//这个大小测试的适配成功
		//QSizeF pageSizeTemp(210, 1000);
		QSizeF pageSizeTemp(210, nPageHeightVal);
		printer.setPageSize(QPageSize(pageSizeTemp, QPageSize::Millimeter));
	}
	else
	{
		printer.setPageSize(QPageSize(QPageSize::A4));// 设置页面大小为A4
	}


	painter.setPen(penNormal);
	int nRowCount = 3;  // 表格行数
	int nColumnCount = 4;  // 表格列数

	int nCellWidth = 140;  // 单元格宽度
	int nCellHeight = 30;  // 单元格高度

	int cellStartX = 8;//表格起点坐标X

	//printer.setPageSize(QPageSize(QPageSize::A4));// 设置页面大小为A4
	printer.newPage(); // 添加新的一页


	// 绘制第一行合并的单元格
	QRect merged_cell_rectVoice(cellStartX, 60 - 40, nCellWidth * 4, nCellHeight * 2);//高度占2行
	painter.drawRect(merged_cell_rectVoice);  // 绘制单元格边框
	painter.drawText(merged_cell_rectVoice, Qt::AlignCenter, A2T("连续托辊检测"));  // 绘制单元格内容

	// 绘制第二行标题栏
	int nRowTemporary = 2;//从2行开始
	nRowTemporary += 1;//因为第一行用了两行的高度，所有要+1
	for (int nCol = 0; nCol < nColumnCount; nCol++)//4列
	{
		QRect cell_rect(cellStartX + nCol * nCellWidth, 40 + nRowTemporary * nCellHeight - 40, nCellWidth, nCellHeight);
		painter.drawRect(cell_rect);  // 绘制单元格边框
		//painter.drawText(cell_rect, Qt::AlignCenter, QString::number(QRandomGenerator::global()->bounded(100)));  // 填充随机内容


		if (nCol == 0)
		{
			painter.setFont(fontPage2JiaCu);
			painter.drawText(cell_rect, Qt::AlignCenter, A2T("位置"));//米(托辊号)
		}
		else if (nCol == 1)
		{
			painter.setFont(fontPage2JiaCu);
			painter.drawText(cell_rect, Qt::AlignCenter, A2T("测量值"));
		}
		else if (nCol == 2)
		{
			painter.setFont(fontPage2JiaCu);
			painter.drawText(cell_rect, Qt::AlignCenter, A2T("状态"));
		}
		else if (nCol == 3)
		{
			painter.setFont(fontPage2JiaCu);
			painter.drawText(cell_rect, Qt::AlignCenter, A2T("阈值"));
		}


	}
	nRowTemporary++;

	//遍历红外报警列表，往后继续绘制
	for (QMap<int, QVector<CPdfCotIrInfo>>::iterator i = mapCotIrInfo.begin(); i != mapCotIrInfo.end(); i++)
	{
		QVector<CPdfCotIrInfo> vecData = i.value();

		for (int nAlmIndex = 0; nAlmIndex < vecData.size(); nAlmIndex++)
		{
			//============红外测温
			//先绘制第一列合并上下两个单元格 位置
			QRect merged_cell_Temp1(cellStartX, 40 + nRowTemporary * nCellHeight - 40, nCellWidth, nCellHeight * 6);//6倍的高度,因为要放图片 150
			painter.drawRect(merged_cell_Temp1);  // 绘制单元格边框
			painter.setFont(fontPage2JiaCu);
			QString sLoca = A2T("托辊:%1(%2m)").arg(vecData[nAlmIndex].m_sRollerDesc).arg(QString::number(vecData[nAlmIndex].m_dLocation, 'f', 1));
			painter.drawText(merged_cell_Temp1, Qt::TextWordWrap | Qt::AlignCenter, sLoca);

			//绘制右侧的测量值、状态、备注这3个信息单元格
			painter.setFont(fontPage2Normal);
			for (int nCol = 1; nCol < nColumnCount; nCol++)//后面3列
			{
				QRect cell_rectTemp(cellStartX + nCol * nCellWidth, 40 + nRowTemporary * nCellHeight - 40, nCellWidth, nCellHeight);//150
				painter.drawRect(cell_rectTemp);// 绘制单元格边框

				if (nCol == 1)//测量值
				{
					if (0 == vecData[nAlmIndex].m_nAlmState)
					{
						painter.setPen(penNormal);
					}
					else
					{
						painter.setPen(penNormalRed);//设置字体颜色为红色
					}


					painter.drawText(cell_rectTemp, Qt::AlignCenter, A2T("最高") + QString::number(vecData[nAlmIndex].m_doMeasurementVal) + A2T("℃"));
					painter.setPen(penNormal);//设置字体颜色恢复
				}
				else if (nCol == 2)//状态
				{
					if (0 == vecData[nAlmIndex].m_nAlmState)
					{
						painter.setPen(penNormal);
					}
					else
					{
						painter.setPen(penNormalRed);//设置字体颜色为红色
					}

					painter.drawText(cell_rectTemp, Qt::AlignCenter, vecData[nAlmIndex].m_strAlmDesc);
					painter.setPen(penNormal);//设置字体颜色恢复
				}
				else if (nCol == 3)//备注
				{
					painter.drawText(cell_rectTemp, Qt::AlignCenter, vecData[nAlmIndex].m_sRemark);
				}
			}

			//绘制图片栏
			QPixmap pixmapPic(vecData[nAlmIndex].m_sPictureAddress);
			painter.drawPixmap(QRect(cellStartX + nCellWidth, 40 + (nRowTemporary + 1) * nCellHeight - 40, nCellWidth * 2, nCellHeight * 5), pixmapPic);

			//绘制图片备注栏
			QRect mergedCellTemp(cellStartX + 3 * nCellWidth, 40 + (nRowTemporary + 1) * nCellHeight - 40, nCellWidth, nCellHeight * 5);
			painter.drawRect(mergedCellTemp);  // 绘制单元格边框

			painter.setFont(fontPage2SmallNormal);
			painter.drawText(mergedCellTemp, Qt::TextWordWrap | Qt::AlignCenter, vecData[nAlmIndex].m_sPictureRemark);
			painter.setFont(fontPage2Normal);


			nRowTemporary += 6;
		}
	}

}

//绘制新的一个连续红外+连续声音在一起
void COptPdfRptBase::drawNewPageCotAll(QMap<int, QVector<CPdfCotIrInfo>> &mapCotIrInfo, QMap<int, QVector<CPdfCotVoiceInfo>> &mapCotVoice, QMap<int, QVector<CPdfCotImageInfo>> &mapCotImage, QPainter &painter, QPrinter &printer)
{
	QPen penNormal(Qt::black, 1, Qt::SolidLine);// 设置边框的颜色和宽度 正常黑色
	QPen penNormalRed(Qt::red, 1, Qt::SolidLine);// 设置边框的颜色和宽度 正常红色
	QPen penJiaCu(Qt::black, 3, Qt::SolidLine);// 设置边框的颜色和宽度 正常黑色加粗

	QFont fontPage2Normal("Arial", 18, QFont::Normal);//普通
	QFont fontPage2Red("Arial", 18, QFont::Bold);//普通红色
	QFont fontPage2SmallNormal("Arial", 12, QFont::Normal);//普通
	QFont fontPage2JiaCu("Arial", 18, QFont::Bold);//加粗
	QFont fontPage2SmallJiaCu("Arial", 14, QFont::Bold);//加粗
	QFont fontPage2Bold("Arial", 24, QFont::Bold);//加粗

	QString strTableCaption = "";

	//先根据是否有连续噪声、连续图像，赋值绘制类型
	int nDrawType = 0;//0:只绘制 红外 1:绘制红外+声音 2:绘制红外+声音+图像
	if (mapCotVoice.size() == 0 && mapCotImage.size() == 0)
	{
		nDrawType = 0;//只绘制红外
	}
	else if (mapCotVoice.size() > 0 && mapCotImage.size() == 0)
	{
		nDrawType = 1;//绘制红外+声音
	}
	else if (mapCotVoice.size() > 0 && mapCotImage.size() > 0)
	{
		nDrawType = 2;//红外+声音+图像
	}


	//先统计总数
	int nCount = 0;
	for (QMap<int, QVector<CPdfCotIrInfo>>::iterator i = mapCotIrInfo.begin(); i != mapCotIrInfo.end(); i++)
	{
		nCount += i.value().size();
	}


	//先计算A4纸是否满足 不然就要自定义高度
	if (nCount > 3)//信息列表大于3行,A4纸大小就不够了
	{
		//int nPageHeightVal = 297 + (CRobData.m_VecCotVoiceInfo.size() - 21 + 1) * 11;//这个大小测试的适配成功
		//int nPageHeightVal = 297 + (nCount * 7 - 21 + 1) * 11;//这个大小测试的适配成功
		//int nPageHeightVal = 297 + (nCount * 12 - 21 + 1) * 11;//这个大小测试的适配成功

		int nPageHeightVal = 297;
		switch (nDrawType)
		{
		case 0:
			nPageHeightVal = 297 + (nCount * 6 - 21 + 1) * 11;
			break;
		case 1:
			nPageHeightVal = 297 + (nCount * 7 - 21 + 1) * 11;
			break;
		case 2:
			nPageHeightVal = 297 + (nCount * 12 - 21 + 1) * 11;
			break;
		default:
			break;
		}

		//QSizeF pageSizeTemp(210, 1000);
		QSizeF pageSizeTemp(210, nPageHeightVal);
		printer.setPageSize(QPageSize(pageSizeTemp, QPageSize::Millimeter));
	}
	else
	{
		printer.setPageSize(QPageSize(QPageSize::A4));// 设置页面大小为A4
	}


	painter.setPen(penNormal);

	int nRowCount = 3;  // 表格行数
	int nColumnCount = 4;  // 表格列数
	int nCellWidth = 140;  // 单元格宽度
	int nCellHeight = 30;  // 单元格高度

	int cellStartX = 8;//表格起点坐标X

	//printer.setPageSize(QPageSize(QPageSize::A4));// 设置页面大小为A4
	printer.newPage(); // 添加新的一页


	{
		// 绘制第一行合并的单元格
		QRect mergedCellRect(cellStartX, 60 - 40, nCellWidth * 4, nCellHeight * 2);//高度占2行
		painter.drawRect(mergedCellRect);  // 绘制单元格边框
		painter.drawText(mergedCellRect, Qt::AlignCenter, A2T("连续托辊检测"));  // 绘制单元格内容
	}


	// 绘制第二行标题栏
	int nRowTemporary = 2;//从2行开始
	nRowTemporary += 1;//因为第一行用了两行的高度，所有要+1
	for (int nCol = 0; nCol < nColumnCount; nCol++)//4列
	{
		QRect cell_rect(cellStartX + nCol * nCellWidth, 40 + nRowTemporary * nCellHeight - 40, nCellWidth, nCellHeight);
		painter.drawRect(cell_rect);  // 绘制单元格边框
		//painter.drawText(cell_rect, Qt::AlignCenter, QString::number(QRandomGenerator::global()->bounded(100)));  // 填充随机内容


		if (nCol == 0)
		{
			painter.setFont(fontPage2JiaCu);
			painter.drawText(cell_rect, Qt::AlignCenter, A2T("位置"));//米(托辊号)
		}
		else if (nCol == 1)
		{
			painter.setFont(fontPage2JiaCu);
			painter.drawText(cell_rect, Qt::AlignCenter, A2T("测量值"));
		}
		else if (nCol == 2)
		{
			painter.setFont(fontPage2JiaCu);
			painter.drawText(cell_rect, Qt::AlignCenter, A2T("状态"));
		}
		else if (nCol == 3)
		{
			painter.setFont(fontPage2JiaCu);
			painter.drawText(cell_rect, Qt::AlignCenter, A2T("阈值"));
		}


	}
	nRowTemporary++;

	//遍历红外报警列表，往后继续绘制
	for (QMap<int, QVector<CPdfCotIrInfo>>::iterator i = mapCotIrInfo.begin(); i != mapCotIrInfo.end(); i++)
	{
		QVector<CPdfCotIrInfo> vecDataIr = i.value();
		QVector<CPdfCotVoiceInfo> vecDataVoice;
		QVector<CPdfCotImageInfo> vecDataImage;
		if (mapCotVoice.contains(i.key()))
		{
			vecDataVoice = mapCotVoice[i.key()];
		}
		if (mapCotImage.contains(i.key()))
		{
			vecDataImage = mapCotImage[i.key()];
		}

		//调用绘制一组函数
		drawGroupCot(nDrawType, nRowTemporary, vecDataIr, vecDataVoice, vecDataImage, painter);

	}
}

//画一组连续检测
void COptPdfRptBase::drawGroupCot(int nDrawType, int &nRowTemporary, QVector<CPdfCotIrInfo> vecDataIr, QVector<CPdfCotVoiceInfo> vecDataVoice, QVector<CPdfCotImageInfo> vecDataImage, QPainter &painter)
{
	QPen penNormal(Qt::black, 1, Qt::SolidLine);// 设置边框的颜色和宽度 正常黑色
	QPen penNormalRed(Qt::red, 1, Qt::SolidLine);// 设置边框的颜色和宽度 正常红色
	QPen penJiaCu(Qt::black, 3, Qt::SolidLine);// 设置边框的颜色和宽度 正常黑色加粗

	QFont fontPage2Normal("Arial", 18, QFont::Normal);//普通
	QFont fontPage2Red("Arial", 18, QFont::Bold);//普通红色
	QFont fontPage2SmallNormal("Arial", 12, QFont::Normal);//普通
	QFont fontPage2JiaCu("Arial", 18, QFont::Bold);//加粗
	QFont fontPage2SmallJiaCu("Arial", 14, QFont::Bold);//加粗
	QFont fontPage2Bold("Arial", 24, QFont::Bold);//加粗

	int nCellWidth = 140;  // 单元格宽度
	int nCellHeight = 30;  // 单元格高度
	int cellStartX = 8;//表格起点坐标X
	int nColumnCount = 4;  // 表格列数

	int nMergeCellsCnt = 6;//合并单元格格数
	switch (nDrawType)
	{
	case 0:
		nMergeCellsCnt = 6;
		break;
	case 1:
		nMergeCellsCnt = 7;
		break;
	case 2:
		nMergeCellsCnt = 12;
		break;
	default:
		break;
	}


	for (int nAlmIndex = 0; nAlmIndex < vecDataIr.size(); nAlmIndex++)
	{
		//============红外测温
		//先绘制第一列合并上下两个单元格 位置
		QRect merged_cell_Temp1(cellStartX, 40 + nRowTemporary * nCellHeight - 40, nCellWidth, nCellHeight * nMergeCellsCnt);//6的红外,因为还要多一行声音检测 + 5行可见光图片
		painter.drawRect(merged_cell_Temp1);  // 绘制单元格边框
		painter.setFont(fontPage2JiaCu);
		QString sBelongTier = "";
		if (vecDataIr[nAlmIndex].nBelongTier == 0)
		{
			sBelongTier = A2T("上");
		}
		else
		{
			sBelongTier = A2T("下");
		}

		//QString sLoca = A2T("托辊:%1(%2m)").arg(vecData[nAlmIndex].m_sRollerDesc).arg(QString::number(vecData[nAlmIndex].m_dLocation, 'f', 1));
		QString sLoca = A2T("托辊:%1(%2)").arg(vecDataIr[nAlmIndex].m_sRollerDesc).arg(sBelongTier);
		painter.drawText(merged_cell_Temp1, Qt::TextWordWrap | Qt::AlignCenter, sLoca);

		//绘制右侧的测量值、状态、备注这3个信息单元格
		painter.setFont(fontPage2Normal);
		//红外测温
		for (int nCol = 1; nCol < nColumnCount; nCol++)//后面3列
		{
			QRect cell_rectTemp(cellStartX + nCol * nCellWidth, 40 + nRowTemporary * nCellHeight - 40, nCellWidth, nCellHeight);//150
			painter.drawRect(cell_rectTemp);// 绘制单元格边框

			if (nCol == 1)//测量值
			{
				if (0 == vecDataIr[nAlmIndex].m_nAlmState)
				{
					painter.setPen(penNormal);
				}
				else
				{
					painter.setPen(penNormalRed);//设置字体颜色为红色
				}


				painter.drawText(cell_rectTemp, Qt::AlignCenter, A2T("温度:最高") + QString::number(vecDataIr[nAlmIndex].m_doMeasurementVal) + A2T("℃"));
				painter.setPen(penNormal);//设置字体颜色恢复
			}
			else if (nCol == 2)//状态
			{
				if (0 == vecDataIr[nAlmIndex].m_nAlmState)
				{
					painter.setPen(penNormal);
				}
				else
				{
					painter.setPen(penNormalRed);//设置字体颜色为红色
				}

				painter.drawText(cell_rectTemp, Qt::AlignCenter, vecDataIr[nAlmIndex].m_strAlmDesc);
				painter.setPen(penNormal);//设置字体颜色恢复
			}
			else if (nCol == 3)//阈值
			{
				painter.drawText(cell_rectTemp, Qt::AlignCenter, vecDataIr[nAlmIndex].m_sRemark);
			}
		}

		//分类型绘制后面的
		if (nDrawType == 0)//只绘制红外
		{
			//绘制红外图片栏
			{

				QPixmap pixmapPic(vecDataIr[nAlmIndex].m_sPictureAddress);
				painter.drawPixmap(QRect(cellStartX + nCellWidth, 40 + (nRowTemporary + 1) * nCellHeight - 40, nCellWidth * 2, nCellHeight * 5), pixmapPic);

				//绘制图片备注栏
				QRect mergedCellTemp(cellStartX + 3 * nCellWidth, 40 + (nRowTemporary + 1) * nCellHeight - 40, nCellWidth, nCellHeight * 5);
				painter.drawRect(mergedCellTemp);  // 绘制单元格边框

				painter.setFont(fontPage2SmallNormal);
				painter.drawText(mergedCellTemp, Qt::TextWordWrap | Qt::AlignCenter, vecDataIr[nAlmIndex].m_sPictureRemark);
				painter.setFont(fontPage2Normal);
			}


		}
		else if (nDrawType == 1)//红外+噪声
		{
			//绘制一行噪声
			{
				for (int nCol = 1; nCol < nColumnCount; nCol++)//后面3列
				{
					QRect cell_rectTemp(cellStartX + nCol * nCellWidth, 40 + (nRowTemporary + 1) * nCellHeight - 40, nCellWidth, nCellHeight);//150
					painter.drawRect(cell_rectTemp);// 绘制单元格边框

					int nVoiceDataIndex = -1;

					for (int nInx = 0; nInx < vecDataVoice.size(); nInx++)
					{
						if (vecDataVoice[nInx].nBelongTier == vecDataIr[nAlmIndex].nBelongTier)
						{
							nVoiceDataIndex = nInx;
							break;
						}
					}


					if (nCol == 1)//测量值
					{
						if (nVoiceDataIndex == -1)
						{
							painter.setPen(penNormal);
							painter.drawText(cell_rectTemp, Qt::AlignCenter, A2T("/"));
						}
						else
						{
							if (0 == vecDataVoice[nVoiceDataIndex].m_nAlmState)
							{
								painter.setPen(penNormal);
							}
							else
							{
								painter.setPen(penNormalRed);//设置字体颜色为红色
							}


							painter.drawText(cell_rectTemp, Qt::AlignCenter, A2T("噪声:") + QString::number(vecDataVoice[nVoiceDataIndex].m_dValue, 'f', 1) + A2T("dB"));
							painter.setPen(penNormal);//设置字体颜色恢复
						}


					}
					else if (nCol == 2)//状态
					{
						if (nVoiceDataIndex == -1)
						{
							painter.setPen(penNormal);
							painter.drawText(cell_rectTemp, Qt::AlignCenter, A2T("/"));
						}
						else
						{
							if (0 == vecDataVoice[nVoiceDataIndex].m_nAlmState)
							{
								painter.setPen(penNormal);
							}
							else
							{
								painter.setPen(penNormalRed);//设置字体颜色为红色
							}

							painter.drawText(cell_rectTemp, Qt::AlignCenter, vecDataVoice[nVoiceDataIndex].m_strAlmDesc);
							painter.setPen(penNormal);//设置字体颜色恢复
						}

					}
					else if (nCol == 3)//阈值
					{
						if (nVoiceDataIndex == -1)
						{
							painter.drawText(cell_rectTemp, Qt::AlignCenter, ("/"));
						}
						else
						{
							painter.drawText(cell_rectTemp, Qt::AlignCenter, vecDataVoice[nVoiceDataIndex].m_sRemark);
						}

					}
				}
			}

			//绘制红外图片栏
			{

				QPixmap pixmapPic(vecDataIr[nAlmIndex].m_sPictureAddress);
				painter.drawPixmap(QRect(cellStartX + nCellWidth, 40 + (nRowTemporary + 2) * nCellHeight - 40, nCellWidth * 2, nCellHeight * 5), pixmapPic);

				//绘制图片备注栏
				QRect mergedCellTemp(cellStartX + 3 * nCellWidth, 40 + (nRowTemporary + 2) * nCellHeight - 40, nCellWidth, nCellHeight * 5);
				painter.drawRect(mergedCellTemp);  // 绘制单元格边框

				painter.setFont(fontPage2SmallNormal);
				painter.drawText(mergedCellTemp, Qt::TextWordWrap | Qt::AlignCenter, vecDataIr[nAlmIndex].m_sPictureRemark);
				painter.setFont(fontPage2Normal);
			}

			//绘制图像图片栏
			{
				int nImageDataIndex = -1;

				for (int nInx = 0; nInx < vecDataImage.size(); nInx++)
				{
					if (vecDataImage[nInx].nBelongTier == vecDataIr[nAlmIndex].nBelongTier)
					{
						nImageDataIndex = nInx;
						break;
					}
				}

				if (nImageDataIndex == -1)
				{

				}
				else
				{
					//绘制图片栏
					QString sHttpPicUrl = vecDataImage[nImageDataIndex].m_sHttpPicAddr;
					CImageDownloader downPic(sHttpPicUrl);
					QPixmap pixmapNow;
					if (sHttpPicUrl.size() > 0)
					{
						downPic.getNewDlPixmap(pixmapNow);
					}
					painter.drawPixmap(QRect(cellStartX + nCellWidth, 40 + (nRowTemporary + 2 + 5) * nCellHeight - 40, nCellWidth * 2, nCellHeight * 5), pixmapNow);

					//绘制图片备注栏
					QRect mergedCellTemp(cellStartX + 3 * nCellWidth, 40 + (nRowTemporary + 2 + 5) * nCellHeight - 40, nCellWidth, nCellHeight * 5);
					painter.drawRect(mergedCellTemp);  // 绘制单元格边框

					painter.setFont(fontPage2SmallNormal);
					painter.drawText(mergedCellTemp, Qt::TextWordWrap | Qt::AlignCenter, vecDataImage[nImageDataIndex].m_sPictureRemark);
					painter.setFont(fontPage2Normal);
				}

			}

		}
		else if (nDrawType == 2)//红外+噪声+图像
		{

			//绘制一行噪声
			{
				for (int nCol = 1; nCol < nColumnCount; nCol++)//后面3列
				{
					QRect cell_rectTemp(cellStartX + nCol * nCellWidth, 40 + (nRowTemporary + 1) * nCellHeight - 40, nCellWidth, nCellHeight);//150
					painter.drawRect(cell_rectTemp);// 绘制单元格边框

					int nVoiceDataIndex = -1;

					for (int nInx = 0; nInx < vecDataVoice.size(); nInx++)
					{
						if (vecDataVoice[nInx].nBelongTier == vecDataIr[nAlmIndex].nBelongTier)
						{
							nVoiceDataIndex = nInx;
							break;
						}
					}


					if (nCol == 1)//测量值
					{
						if (nVoiceDataIndex == -1)
						{
							painter.setPen(penNormal);
							painter.drawText(cell_rectTemp, Qt::AlignCenter, A2T("/"));
						}
						else
						{
							if (0 == vecDataVoice[nVoiceDataIndex].m_nAlmState)
							{
								painter.setPen(penNormal);
							}
							else
							{
								painter.setPen(penNormalRed);//设置字体颜色为红色
							}


							painter.drawText(cell_rectTemp, Qt::AlignCenter, A2T("噪声:") + QString::number(vecDataVoice[nVoiceDataIndex].m_dValue, 'f', 1) + A2T("dB"));
							painter.setPen(penNormal);//设置字体颜色恢复
						}


					}
					else if (nCol == 2)//状态
					{
						if (nVoiceDataIndex == -1)
						{
							painter.setPen(penNormal);
							painter.drawText(cell_rectTemp, Qt::AlignCenter, A2T("/"));
						}
						else
						{
							if (0 == vecDataVoice[nVoiceDataIndex].m_nAlmState)
							{
								painter.setPen(penNormal);
							}
							else
							{
								painter.setPen(penNormalRed);//设置字体颜色为红色
							}

							painter.drawText(cell_rectTemp, Qt::AlignCenter, vecDataVoice[nVoiceDataIndex].m_strAlmDesc);
							painter.setPen(penNormal);//设置字体颜色恢复
						}

					}
					else if (nCol == 3)//阈值
					{
						if (nVoiceDataIndex == -1)
						{
							painter.drawText(cell_rectTemp, Qt::AlignCenter, ("/"));
						}
						else
						{
							painter.drawText(cell_rectTemp, Qt::AlignCenter, vecDataVoice[nVoiceDataIndex].m_sRemark);
						}

					}
				}
			}

			//绘制红外图片栏
			{

				QPixmap pixmapPic(vecDataIr[nAlmIndex].m_sPictureAddress);
				painter.drawPixmap(QRect(cellStartX + nCellWidth, 40 + (nRowTemporary + 2) * nCellHeight - 40, nCellWidth * 2, nCellHeight * 5), pixmapPic);

				//绘制图片备注栏
				QRect mergedCellTemp(cellStartX + 3 * nCellWidth, 40 + (nRowTemporary + 2) * nCellHeight - 40, nCellWidth, nCellHeight * 5);
				painter.drawRect(mergedCellTemp);  // 绘制单元格边框

				painter.setFont(fontPage2SmallNormal);
				painter.drawText(mergedCellTemp, Qt::TextWordWrap | Qt::AlignCenter, vecDataIr[nAlmIndex].m_sPictureRemark);
				painter.setFont(fontPage2Normal);
			}

			//绘制图像图片栏
			{
				int nImageDataIndex = -1;

				for (int nInx = 0; nInx < vecDataImage.size(); nInx++)
				{
					if (vecDataImage[nInx].nBelongTier == vecDataIr[nAlmIndex].nBelongTier)
					{
						nImageDataIndex = nInx;
						break;
					}
				}

				if (nImageDataIndex == -1)
				{

				}
				else
				{
					//绘制图片栏
					QString sHttpPicUrl = vecDataImage[nImageDataIndex].m_sHttpPicAddr;
					CImageDownloader downPic(sHttpPicUrl);
					QPixmap pixmapNow;
					if (sHttpPicUrl.size() > 0)
					{
						downPic.getNewDlPixmap(pixmapNow);
					}
					painter.drawPixmap(QRect(cellStartX + nCellWidth, 40 + (nRowTemporary + 2 + 5) * nCellHeight - 40, nCellWidth * 2, nCellHeight * 5), pixmapNow);

					//绘制图片备注栏
					QRect mergedCellTemp(cellStartX + 3 * nCellWidth, 40 + (nRowTemporary + 2 + 5) * nCellHeight - 40, nCellWidth, nCellHeight * 5);
					painter.drawRect(mergedCellTemp);  // 绘制单元格边框

					painter.setFont(fontPage2SmallNormal);
					painter.drawText(mergedCellTemp, Qt::TextWordWrap | Qt::AlignCenter, vecDataImage[nImageDataIndex].m_sPictureRemark);
					painter.setFont(fontPage2Normal);
				}

			}

		}

		nRowTemporary += nMergeCellsCnt;
	}
}


//画一行表格合并左1右3
void COptPdfRptBase::drawRowFormMergeL1R3(int nCellStartX, int nCellStartY, int nCellWidth, int nCellHeight, QString sLeftInfo, QString sRightInfo, QPainter &painter)
{
	QFont fontNormal("Arial", 18, QFont::Normal);//普通
	QFont fontJiaCu("Arial", 18, QFont::Bold);//加粗

	//绘制左侧合并的1列
	{
		painter.setFont(fontJiaCu);
		QRect mergedCellRect(nCellStartX, nCellStartY, nCellWidth, nCellHeight);
		painter.drawRect(mergedCellRect);  // 绘制1列单元格边框
		painter.drawText(mergedCellRect, Qt::AlignCenter, sLeftInfo);
	}
	//绘制右侧合并的3列
	{
		painter.setFont(fontNormal);
		QRect mergedCellRect(nCellStartX + nCellWidth, nCellStartY, nCellWidth * 3, nCellHeight);
		painter.drawRect(mergedCellRect);// 绘制3列合并单元格边框
		painter.drawText(mergedCellRect, Qt::AlignCenter, sRightInfo);
	}
	
}

//画一行表格4列
void COptPdfRptBase::drawRowFormCol4(int nCellStartX, int nCellStartY, int nCellWidth, int nCellHeight, QVector<QString> vecInfo, QPainter &painter)
{
	if (vecInfo.size() != 4)
	{
		return;
	}

	QFont fontNormal("Arial", 18, QFont::Normal);//普通
	QFont fontJiaCu("Arial", 18, QFont::Bold);//加粗
	QPen penNormal(Qt::black, 1, Qt::SolidLine);// 设置边框的颜色和宽度 正常黑色
	QPen penNormalRed(Qt::red, 1, Qt::SolidLine);// 设置边框的颜色和宽度 正常红色

	painter.setPen(penNormal);

	//绘制第一列
	{
		painter.setFont(fontJiaCu);
		QRect mergedCellRect(nCellStartX, nCellStartY, nCellWidth, nCellHeight);
		painter.drawRect(mergedCellRect);  // 绘制1列单元格边框
		painter.drawText(mergedCellRect, Qt::AlignCenter, vecInfo[0]);
	}
	//绘制第二列
	{
		painter.setFont(fontNormal);
		QRect mergedCellRect(nCellStartX + nCellWidth, nCellStartY, nCellWidth, nCellHeight);
		painter.drawRect(mergedCellRect);// 绘制3列合并单元格边框
		painter.drawText(mergedCellRect, Qt::AlignCenter, vecInfo[1]);
	}
	//绘制第三列
	{
		painter.setFont(fontJiaCu);
		QRect mergedCellRect(nCellStartX + nCellWidth * 2, nCellStartY, nCellWidth, nCellHeight);
		painter.drawRect(mergedCellRect);// 绘制3列合并单元格边框
		painter.drawText(mergedCellRect, Qt::AlignCenter, vecInfo[2]);
	}
	//绘制第四列
	{
		painter.setFont(fontNormal);
		QRect mergedCellRect(nCellStartX + nCellWidth * 3, nCellStartY, nCellWidth, nCellHeight);
		painter.drawRect(mergedCellRect);// 绘制3列合并单元格边框
		painter.drawText(mergedCellRect, Qt::AlignCenter, vecInfo[3]);
	}
}

//画一行表格4列
void COptPdfRptBase::drawRowFormCol4(int nCellStartX, int nCellStartY, int nCellWidth, int nCellHeight, QVector<QString> vecInfo, QPainter &painter, QVector<bool> vecAbnormal)
{
	if (vecInfo.size() != 4 || vecAbnormal.size() != 4)
	{
		return;
	}

	QFont fontNormal("Arial", 18, QFont::Normal);//普通
	QFont fontJiaCu("Arial", 18, QFont::Bold);//加粗
	QPen penNormal(Qt::black, 1, Qt::SolidLine);// 设置边框的颜色和宽度 正常黑色
	QPen penNormalRed(Qt::red, 1, Qt::SolidLine);// 设置边框的颜色和宽度 正常红色

	

	//绘制第一列
	{
		painter.setPen(penNormal);
		painter.setFont(fontJiaCu);
		QRect mergedCellRect(nCellStartX, nCellStartY, nCellWidth, nCellHeight);
		painter.drawRect(mergedCellRect);  // 绘制1列单元格边框

		if (false == vecAbnormal[0])
		{
			painter.setPen(penNormal);
		}
		else
		{
			painter.setPen(penNormalRed);
		}
		painter.drawText(mergedCellRect, Qt::AlignCenter, vecInfo[0]);
	}
	//绘制第二列
	{
		painter.setPen(penNormal);
		painter.setFont(fontNormal);
		QRect mergedCellRect(nCellStartX + nCellWidth, nCellStartY, nCellWidth, nCellHeight);
		painter.drawRect(mergedCellRect);// 绘制3列合并单元格边框

		if (false == vecAbnormal[1])
		{
			painter.setPen(penNormal);
		}
		else
		{
			painter.setPen(penNormalRed);
		}
		painter.drawText(mergedCellRect, Qt::AlignCenter, vecInfo[1]);
	}
	//绘制第三列
	{
		painter.setPen(penNormal);
		painter.setFont(fontJiaCu);
		QRect mergedCellRect(nCellStartX + nCellWidth * 2, nCellStartY, nCellWidth, nCellHeight);
		painter.drawRect(mergedCellRect);// 绘制3列合并单元格边框

		if (false == vecAbnormal[2])
		{
			painter.setPen(penNormal);
		}
		else
		{
			painter.setPen(penNormalRed);
		}
		painter.drawText(mergedCellRect, Qt::AlignCenter, vecInfo[2]);
	}
	//绘制第四列
	{
		painter.setPen(penNormal);
		painter.setFont(fontNormal);
		QRect mergedCellRect(nCellStartX + nCellWidth * 3, nCellStartY, nCellWidth, nCellHeight);
		painter.drawRect(mergedCellRect);// 绘制3列合并单元格边框

		if (false == vecAbnormal[3])
		{
			painter.setPen(penNormal);
		}
		else
		{
			painter.setPen(penNormalRed);
		}
		painter.drawText(mergedCellRect, Qt::AlignCenter, vecInfo[3]);
	}
}

//绘制合并多行1列
void COptPdfRptBase::drawMergeMultiRowOneCol(int nCellStartX, int nCellStartY, int nCellWidth, int nCellHeight, int nMergeRowNum, QString sDataInfo, QPainter &painter, bool bAbnormal)
{
	QFont fontNormal("Arial", 18, QFont::Normal);//普通
	QFont fontJiaCu("Arial", 18, QFont::Bold);//加粗
	QPen penNormal(Qt::black, 1, Qt::SolidLine);// 设置边框的颜色和宽度 正常黑色
	QPen penNormalRed(Qt::red, 1, Qt::SolidLine);// 设置边框的颜色和宽度 正常红色

	//绘制合并的1列多行
	{
		painter.setPen(penNormal);
		painter.setFont(fontJiaCu);
		QRect mergedCellRect(nCellStartX, nCellStartY, nCellWidth, nCellHeight * nMergeRowNum);
		painter.drawRect(mergedCellRect);  // 绘制单元格边框

		if (false == bAbnormal)
		{
			painter.setPen(penNormal);
		}
		else
		{
			painter.setPen(penNormalRed);
		}
		painter.drawText(mergedCellRect, Qt::AlignCenter, sDataInfo);
	}
}

//绘制合并多列1行
void COptPdfRptBase::drawMergeMultiColOneRow(int nCellStartX, int nCellStartY, int nCellWidth, int nCellHeight, int nMergeColNum, QString sDataInfo, QPainter &painter, bool bAbnormal)
{
	int nWordRightSkewing = 3;//文字向右偏移量(居中对齐不需要,只有左对齐需要，不然会和表格左侧重叠)

	QFont fontNormal("Arial", 18, QFont::Normal);//普通
	QFont fontJiaCu("Arial", 18, QFont::Bold);//加粗
	QPen penNormal(Qt::black, 1, Qt::SolidLine);// 设置边框的颜色和宽度 正常黑色
	QPen penNormalRed(Qt::red, 1, Qt::SolidLine);// 设置边框的颜色和宽度 正常红色

	//绘制合并的1行多列
	{
		painter.setPen(penNormal);
		painter.setFont(fontNormal);
		QRect mergedCellRect(nCellStartX, nCellStartY, nCellWidth * nMergeColNum, nCellHeight);
		painter.drawRect(mergedCellRect);  // 绘制单元格边框

		if (false == bAbnormal)
		{
			painter.setPen(penNormal);
		}
		else
		{
			painter.setPen(penNormalRed);
		}
		QRect mergedCellRectText(nCellStartX + nWordRightSkewing, nCellStartY, nCellWidth * nMergeColNum, nCellHeight);
		painter.drawText(mergedCellRectText, Qt::AlignLeft | Qt::AlignVCenter, sDataInfo);
	}
}
